import {getTemplateBody} from "@/utils/auth";

const PAGE_SIZES = 10
export {PAGE_SIZES}

export const MAPPER = {
  9: {'id': 9, 'name': '机械特性调试', 'type': 3},
  12: {'id': 12, 'name': '产品下线报告打印装', 'type': 4},
  10: {'id': 10, 'name': '机械特性测试', 'type': 3},
  11: {'id': 11, 'name': '终检面板安装', 'type': 3},
  8: {'id': 8, 'name': '极柱安装', 'type': 3},
  6: {'id': 6, 'name': '底盘车触臂触头安装', 'type': 2},
  7: {'id': 7, 'name': '封板安装检查', 'type': 2},
  4: {'id': 4, 'name': '磨合试验', 'type': 2},
  3: {'id': 3, 'name': '二次配线', 'type': 2},
  2: {'id': 2, 'name': '机构安装', 'type': 1},
  1: {'id': 1, 'name': '底座零部件安装', 'type': 1},
  5: {'id': 5, 'name': '耐压测试', 'type': 2}
}

export const DATE_RANGE_OPTIONS = {
  shortcuts: [{
    text: '最近一周',
    onClick(picker) {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      picker.$emit('pick', [start, end])
    }
  }, {
    text: '最近一个月',
    onClick(picker) {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      picker.$emit('pick', [start, end])
    }
  }, {
    text: '最近三个月',
    onClick(picker) {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      picker.$emit('pick', [start, end])
    }
  }],
  disabledDate(time) {
    return time.getTime() > Date.now() - 8.64e6
  }
}

export const STATUS_OPTIONS = [{
  label: '流转中',
  value: 1
}, {
  label: '已归档',
  value: 2
}, {
  label: '自由状态',
  value: 3
}]

export const PROBLEM_STATUS = [{
  label: '未处理',
  value: 1
}, {
  label: '已处理',
  value: 2
}, {
  label: '全部',
  value: 3
}]

export const PROBLEM_ENUM = [{
  label: '卡滞',
  value: 1
}, {
  label: '分合',
  value: 2
}, {
  label: '特性',
  value: 3
}, {
  label: '掉漆',
  value: 4
}, {
  label: '采购品',
  value: 5
}, {
  label: '后事故',
  value: 6
}, {
  label: '其他',
  value: 7
}]

export const USER_TYPE_OPTIONS = [
  {
    label: '系统管理员',
    value: 1
  }, {
    label: 'z检查员',
    value: 2
  }, {
    label: '质检员',
    value: 3
  }
]

export function GET_ORDER_NAME(info) {
  const data = JSON.parse(info)
  if (data.projectName !== '' && data.orgNum !== '') {
    return `${data.projectName}_${data.orgNum}_${data.manuNum.substr(-4)}`
  } else {
    return `${data.preNum}_${data.manuNum.substr(-4)}`
  }
}


const removeList = ["num","Zcheck", "Scheck", "Ocheck", "Problem"]

export function getClearFormJson(json) {
  let rt = JSON.parse(json);
  for (let widget of rt.widgetList) {
    for (let j = 0; j < widget.rows.length; j++) {
      let row = widget.rows[j];
      let saveIndex = [];
      for (let i = 0; i < row.cols.length; i++) {
        const col = row.cols[i];
        let flag = true;
        for (let item of col.widgetList) {
          if (item.hasOwnProperty('options') && removeList.includes(item.options.name)) {
            flag = false;
            break;
          }
        }
        if(col.widgetList.length==0) flag=false;
        if (flag) {
          saveIndex.push(i);
        }
      }
      let newCols = [];
      for (let index of saveIndex) {
        newCols.push(row.cols[index]);
      }
      row.cols = newCols;
    }
  }
  return rt;
}


export function getQuestion(oid){

  if (oid === -1) return '无'
  const dict=getTemplateBody()
  return dict[oid]
}
